var express = require('express');
var router = express.Router();
var path = require('path');
var SqliteDB = require('sqlite3').verbose();
var session = require("express-session");

/* GET users listing. */
router.get('/', function(req, res, next) {
  var username = req.query['username'];
  var password = req.query['password'];
  var sql = "select count(1) as num from user where username='"+ username +"' and password='"+password + "'";
  var db = new SqliteDB.Database(path.join(__dirname + '/../db/aiattendance.s3db'));
  var re = '1';
  db.serialize(function(){
    db.get(sql, function(){
      if(arguments.length>=2){      
        var data = arguments[1];
        if(data['num'] == 1){
          req.session['username'] = username;
          re = '0';
        }
      }
      res.send(re);
    })
  });  
  db.close();  
});

module.exports = router;
